<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>等级列表</title>
    <link  href="../../css/mycss.css" rel="stylesheet" type="text/css"/>
    <script src="../../js/jquery.js"></script>
    <script src="../../js/common.js"></script>
    <script>
        window.onload=function (){
            //向后端发送请求，得到回调数据，装入表格中
            $.get(url+"sal/all",function (data){
                //data为一个对象数组
                let str=`<tr>
            <td>编号</td>
            <td>最低工资</td>
            <td>操作</td>
             </tr>`;
                //遍历对象数组
                //参数i表示位置，参数obj表示对象
                $.each(data,function (i,obj){
                str+=`<tr>
            <td>${obj.grade}</td>
            <td>${obj.losal}</td>
            <td>
            <a onclick="del(this,${obj.grade})" href="javascript:">删除</a>
            <a href="salupdate.html?id=${obj.grade}">修改</a>
            </td>
             </tr>`;

                });
                //替换table
                $("table").html(str);
            },"json");
        }
        function del(obj,i){
            let f=confirm("确定删除吗?");
            if(f){
                //向后端发送请求，传递编号，回调处理移除所在行
                $.get(url+"sal/delete",{id:i},function (data){
                    if (data==1){
                        alert("删除成功");
                        obj.parentNode.parentNode.remove();
                    }else{
                        alert("删除失败");
                    }
                });
            }else{
                alert("取消删除");
            }
        }
    </script>
</head>
<body>
<div>
    <table>
        <tr>
            <td>编号</td>
            <td>最低工资</td>
            <td>操作</td>
        </tr>
    </table>
</div>
</body>
</html>